package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import vista.VentanaConsulta;
import vista.VentanaIngredienteModeloTabla;
import modelo.Ingrediente;
import modelo.IngredienteDAO;

public class ControladorIngrediente implements ActionListener {

        
        private VentanaConsulta ventanaConsulta; 
        
        public ControladorIngrediente () {
                super ();
                ventanaConsulta = new VentanaConsulta();
                ventanaConsulta.setLocationRelativeTo(null);
                ventanaConsulta.setVisible(true);
                ventanaConsulta.addListener(this);
        }
        
        public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                
                if(e.getActionCommand().equals("Salir"))
                ventanaConsulta.dispose();
                else if (e.getActionCommand().equals("Consultar")) {
                        IngredienteDAO ingredienteDAO = new IngredienteDAO();
                        List<Ingrediente> ingredient = ingredienteDAO.consultarIngredientes();
                        this.ventanaConsulta.setResultados(new VentanaIngredienteModeloTabla (ingredient));
                }       
        }
}
